package hdpdhl.com.czxy.hdpdhl;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by asus on 2016/3/22.
 */
public class MeFragment extends Fragment {
    private View view;
    //    private TextView textView;
//    public static final int TYPE_TEXT_VARIATION_PERSON_NAME = 96;
    private ListView listView;
    private SimpleAdapter simpleAdapter;
    private List<Map<String, Object>> dataList;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_me, null);
        listView = (ListView) view.findViewById(R.id.listview);
        dataList = new ArrayList<Map<String, Object>>();
        simpleAdapter = new SimpleAdapter(getActivity(), setData(), R.layout.item, new String[]{"text", "answer"}, new int[]{R.id.text, R.id.answer});
        listView.setAdapter(simpleAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                LogUtil.i("当前位置是"+position);
                Intent intent = new Intent("hdpdhl.com.czxy.hdpdhl.ListViewPassOne");
                intent.putExtra("testIntent", String.valueOf(position));
                startActivity(intent);
            }
        });
        return view;
    }

    private List<Map<String, Object>> setData() {

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("text", "如何用mega 2560驱动一个电机");
        map.put("answer", "满意回答：A4988和用专门的步进驱动器控制是一样的~ STEP控制脉冲，DIR控制转向，EN使能控制（电机启停）,MS1~3细分，");
        dataList.add(map);

        Map<String, Object> map1 = new HashMap<String, Object>();
        map1.put("text", "Arduino脱机工作");
        map1.put("answer", "满意回答：一般来说是电源不行造成的，换个充电宝或者质量好点的电池");
        dataList.add(map1);

        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("text", "询问第三方插件arduiblock可视化编程");
        map2.put("answer", "满意回答：首先这款插件叫做ardublock，只需要一个jar包放在指定的文件夹下便可以加载到arduino界面使用了。下载地址：百度网盘 *********");
        dataList.add(map2);

        Map<String, Object> map3 = new HashMap<String, Object>();
        map3.put("text", "舵机的三根线分别接哪里？");
        map3.put("answer", "满意回答：黑 ->GND   红 ->VCC  黄  -> 信号线\n" +
                "棕 ->GND   红-> VCC 橙 ->信号线 ");
        dataList.add(map3);

        Map<String, Object> map4 = new HashMap<String, Object>();
        map4.put("text", "请问ESP8266可以自动自己连某个网址吗?");
        map4.put("answer", "满意回答：当然可以了，你用了tcpserver，肯定有tcp client的");
        dataList.add(map4);
        return dataList;
    }

}
